filethumbnail: Set filechooser::queried after querying
authorGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>
Tue, 28 Feb 2023 16:54:11 +0000 (13:54 -0300)
committerGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>
Tue, 28 Feb 2023 17:18:30 +0000 (14:18 -0300)
commitd8b7c909ea1d14afd366dd2edf5b07696b2b91a6
tree45d068d7417b6e4ed39f05c21dcf1fb5bbe510e1
parent158165f769c6eaee7209b0bd84d480c000d64e07
filethumbnail: Set filechooser::queried after querying

Setting this attribute after querying, but before receiving the
results, can lead to inappropriate behaviour. This can be reproduced
by dragging the scrollbar very quickly in a large directory; after
going up and down a few times, some thumbnails will be wrong.

Without this branch, "wrong" means they'll show the completely wrong
icon or thumbnail, e.g. a folder icon in a video file. With previous
commit, "wrong" means they'll be empty even when there is a thumbnail
available.

The sequence of events that triggers this is as follows:

 1. GtkListItem receives a GFileInfo object and passes it to
    GtkFileThumbnail via expressions

 2. `get_thumbnail()` is called, doesn't find a thumbnail

 3. `filechooser::queried` is not set yet, so it is set to TRUE
      and we call `g_file_query_info_async()`

 4. **Before `thumbnail_queried_cb` is called**, a new GFileInfo
    is set, and we cancel the query initiated in the previous
    step

 5. We now have a GFileInfo with `filechooser::queried` set to
    TRUE, and no thumbnail!

This commit fixes that by only setting the `filechooser::queried`
attribute after the icon is queried. We need to set it in two
situations: when the query is successful, or when the error is
not G_IO_ERROR_CANCELLED. That's because the query was cancelled,
we didn't really perform it!
gtk/gtkfilethumbnail.c